const app = getApp()

Page({
  data: {
    islogin: false,
    id:0,
    zan:'good-job-o',
    zancolor: '#888888',
    ask: [],
    topask:[],
  },
  //监听页面初次载入完成
  onLoad: function (options) {
    var param;
    app.getParam(options,(rel) => {
      param = rel;
    })
    this.setData({
      id: param.id
    });
    this.getView(param.id);
  },
  //生命周期函数--监听页面显示
  onShow: function () {
    this.setData({
      islogin: !app.util().isNull(app.globalData.loginuser),
    })
  },
 //获取推荐
  getView: function (id) {
    var that = this;
    var parms = {
      id: id,
    }
    app.api().Get('api/v1/bestbao/ask/reView', parms, function (result) {
      if (result.code == 200) {
        that.setData({
          ask: result.data,
        });
        that.getList(result.data.category_id);
      }
    })
  },
  //获取API
  getList: function (category_id) {
    let that = this;
    var parms = {
      category_id: category_id,
    }
    app.api().Get('api/v1/bestbao/ask/related', parms, function (result) {
      if (result.code == 200) {
        that.setData({
          topask: result.data
        });
      }
    })
  },
  //去订阅
  doBuyAsk:function () {
    if (app.globalData.isAndroid){
      var param = {
        id: this.data.id,
      }
      app.api().Post("api/v1/bestbao/ask/doBuy", param, (rel) => {
        if (200 == rel.code) {
          app.doWechatPay(rel.data,(res) => {
            this.getView(this.data.id);
          })
        }
      })
    }else{
      app.wxAlert('十分抱歉,由于相关规定,暂不支苹果用户订阅与打赏.');
    }
  },
  //提交问题
  adRepair:function(){
    wx.navigateTo({
      url: '../repair/product?focus=input',
    })
  },
  //暂缓
  onZan: function() {
    if ('good-job-o' == this.data.zan){
      var param = {
        id: this.data.id,
      }
      app.api().Post("api/v1/bestbao/ask/like", param)
      wx.showToast({
        title: '感谢您的反馈',
        icon: 'success',
        duration: 2000
      })
      this.setData({
        zan:'good-job',
        zancolor:'#FFA000'
      })
    }
  }
})